package com.seeyon.apps.kk.form.workflowevent;


import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jdbc.core.JdbcTemplate;

import com.seeyon.apps.collaboration.po.ColSummary;
import com.seeyon.apps.kk.manager.FreemarkFlowManager;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.ctp.common.constants.ApplicationCategoryEnum;
import com.seeyon.ctp.workflow.event.AbstractWorkflowEvent;
import com.seeyon.ctp.workflow.event.WorkflowEventData;
import com.seeyon.kk.utils.ValueUtils;

/**
 *
 * 邀请函处理前事件GFS节点
 * 
 * @author Administrator
 *
 */
public class GFSCLHExtendPlug1 extends AbstractWorkflowEvent {
	private static final Log log = LogFactory.getLog(GFSCLHExtendPlug1.class);
	private FreemarkFlowManager freemarkFlowManager;
	protected JdbcTemplate jdbcTemplate;
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public FreemarkFlowManager getFreemarkFlowManager() {
		return freemarkFlowManager;
	}

	public void setFreemarkFlowManager(FreemarkFlowManager freemarkFlowManager) {
		this.freemarkFlowManager = freemarkFlowManager;
	}

	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return "gfsclhHExtendPlug1";
	}

	@Override
	public String getLabel() {
		// TODO Auto-generated method stub
		return "GS处理后事件1";
	}

	@Override
	public ApplicationCategoryEnum getAppName() {
		return ApplicationCategoryEnum.form;
	}
	 
	// 节点处理事件
	public void onFinishWorkitem(WorkflowEventData data) {
		
		Map<String, Object> formMap = data.getBusinessData();
		FormDataMasterBean fdmb = (FormDataMasterBean) formMap.get("formDataBean");
		ColSummary colSummary=(ColSummary)data.getSummaryObj();
		if(colSummary!=null) {
			log.info("kk:colSummarygetFormRecordid"+colSummary.getFormRecordid());
			log.info("kk:colSummary"+colSummary.getId());
		}

		   String taxpsn = MapUtils.getString(formMap, "field0038");//主表 7041331703390554160
		   
		   log.info("kk:taxpsn"+taxpsn);
		if(taxpsn.equals(ValueUtils.getConfig().getString("kk.InvitationAgree"))) {
			String updateGfsZt = this.freemarkFlowManager.fltTemplateIntoString("invitation/gfsSpArgee.ftl", colSummary);
			this.jdbcTemplate.update(updateGfsZt);
			log.info("KK:"+updateGfsZt);
		}else {
			String updateGfsZt = this.freemarkFlowManager.fltTemplateIntoString("invitation/gfsSpRefuse.ftl", colSummary);
			this.jdbcTemplate.update(updateGfsZt);
			log.info("KK:"+updateGfsZt);
		}
	}
	
	
	

}
